package com.bh.common.config;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云短信服务配置类
 *
 * @author shuangluxing@163.com
 * @date 2023/05/20
 */
@Configuration
public class ALiYunSMSConfig {
    /**
     * 阿里云账号的accessKeyId
     */
    @Value("${aliyun.sms.accessKeyId}")
    private String accessKeyId;
    /**
     * 阿里云账号的accessKeySecret
     */
    @Value("${aliyun.sms.accessKeySecret}")
    private String accessKeySecret;
    /**
     * 短信服务访问的域名
     */
    @Value("${aliyun.sms.endpoint}")
    private String endpoint;

    /*
     * @version V1.0
     * Title: createClient
     * @author Wangwei
     * @description 创建短信服务的代理
     * @createTime  2022/11/7 15:47
     * @param []
     * @return com.aliyun.dysmsapi20170525.Client
     */
    public Client createClient() throws Exception {
        Config config = new Config()
                // 您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = endpoint;
        return new Client(config);
    }
}
